package org.example.mpdemo1.controller;

import org.example.mpdemo1.entity.Message;
import org.example.mpdemo1.mapper.MessageMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
public class MessageController {

    @Autowired
    private MessageMapper messageMapper;

    @GetMapping("/message")
    public List query() {
        return messageMapper.getAll();
    }

    @GetMapping("/message/multithread")
    public List querymt() {
        return messageMapper.getAll();
    }

    @PostMapping("/message")
    public String add(Message message) {
        int i = messageMapper.add(message);
        if (i > 0) {
            return "传输信息成功";
        }else {
            return "传输信息失败";
        }
    }

    @DeleteMapping("/message")
    public void delete() {
        messageMapper.deleteAll();
    }

    @Async("async")
    @DeleteMapping("/message/multithread")
    public void deletemt() {
        messageMapper.deleteAll();
    }

}
